ECS サービスで「新しいデプロイの強制」を実行する方法を教えてください

ECS サービスで「新しいデプロイの強制」を実行する方法を教えてください

Clock Icon2024.09.02

困っていた内容

ECS サービスで「新しいデプロイの強制(Force new deployment)」を実施したいです。
「新しいデプロイの強制」を設定した状態でデプロイをする方法を教えてください。

どう対応すればいいの?

Amazon ECS コンソールの場合はサービスの更新から実施します。
AWS CLI の場合は--force-new-deploymentオプションを設定しupdate-serviceコマンドを実行します。

Amazon ECS コンソールから実行する場合

Amazon ECS コンソールの「クラスター」から、サービスが含まれるクラスターを選択します。

ECS Force new deployment 1

「サービス」タブから対象サービスを選択します。

ECS Force new deployment 2

「サービスを更新」をクリックします。

ECS Force new deployment 3

「新しいデプロイの強制」の選択した状態で「更新」をクリックします。

ECS Force new deployment 4

デプロイが実施されます。

ECS Force new deployment 5

AWS CLIから実行する場合

--force-new-deploymentオプションを設定したupdate-serviceコマンドを実行します。

# コマンド例
$ aws ecs update-service \
  --cluster 【ECS クラスター名】 \
  --service 【ECS サービス名】 \
  --force-new-deployment

# 実行例
$ aws ecs update-service \
  --cluster hato-ecs-cluster \
  --service hato-ecs-service \
  --force-new-deployment
{
    "service": {
        "serviceArn": "arn:aws:ecs:ap-northeast-1:123456789012:service/hato-ecs-cluster/hato-ecs-service",
        "serviceName": "hato-ecs-service",
        "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/hato-ecs-cluster",
        "loadBalancers": [],
        "serviceRegistries": [],
        "status": "ACTIVE",
        "desiredCount": 1,
        "runningCount": 1,
        "pendingCount": 0,
        "capacityProviderStrategy": [
            {
                "capacityProvider": "FARGATE_SPOT",
                "weight": 1,
                "base": 0
            }
        ],
        "platformVersion": "LATEST",
        "platformFamily": "Linux",
        "taskDefinition": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/hato-taskdefinition:15",
        "deploymentConfiguration": {
            "deploymentCircuitBreaker": {
                "enable": false,
                "rollback": false
            },
            "maximumPercent": 200,
            "minimumHealthyPercent": 100,
            "alarms": {
                "alarmNames": [],
                "enable": false,
                "rollback": false
            }
        },
        "deployments": [
            {
                "id": "ecs-svc/2868513750946421708",
                "status": "PRIMARY",
                "taskDefinition": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/hato-taskdefinition:15",
                "desiredCount": 0,
                "pendingCount": 0,
                "runningCount": 0,
                "failedTasks": 0,
                "createdAt": "2024-09-01T15:40:29.995000+09:00",
                "updatedAt": "2024-09-01T15:40:29.995000+09:00",
                "capacityProviderStrategy": [
                    {
                        "capacityProvider": "FARGATE_SPOT",
                        "weight": 1,
                        "base": 0
                    }
                ],
                "platformVersion": "1.4.0",
                "platformFamily": "Linux",
                "networkConfiguration": {
                    "awsvpcConfiguration": {
                        "subnets": [

                            "subnet-123456abcd"
                        ],
                        "securityGroups": [
                            "sg-123abcd"
                        ],
                        "assignPublicIp": "ENABLED"
                    }
                },
                "rolloutState": "IN_PROGRESS",
                "rolloutStateReason": "ECS deployment ecs-svc/2868513750946421708 in progress."
            },
            {
                "id": "ecs-svc/3283513866302867829",
                "status": "ACTIVE",
                "taskDefinition": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/hato-taskdefinition:15",
                "desiredCount": 1,
                "pendingCount": 0,
                "runningCount": 1,
                "failedTasks": 0,
                "createdAt": "2024-09-01T15:38:24.855000+09:00",
                "updatedAt": "2024-09-01T15:39:25.057000+09:00",
                "capacityProviderStrategy": [
                    {
                        "capacityProvider": "FARGATE_SPOT",
                        "weight": 1,
                        "base": 0
                    }
                ],
                "platformVersion": "1.4.0",
                "platformFamily": "Linux",
                "networkConfiguration": {
                    "awsvpcConfiguration": {
                        "subnets": [
                            "subnet-123456abcd"
                        ],
                        "securityGroups": [
                            "sg-123abcd"
                        ],
                        "assignPublicIp": "ENABLED"
                    }
                },
                "rolloutState": "IN_PROGRESS",
                "rolloutStateReason": "ECS deployment ecs-svc/3283513866302867829 in progress."
            },
            {
                "id": "ecs-svc/1915205208403184481",
                "status": "DRAINING",
                "taskDefinition": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/hato-taskdefinition:15",
                "desiredCount": 0,
                "pendingCount": 0,
                "runningCount": 0,
                "failedTasks": 0,
                "createdAt": "2024-09-01T15:30:00.956000+09:00",
                "updatedAt": "2024-09-01T15:40:26.425000+09:00",
                "capacityProviderStrategy": [
                    {
                        "capacityProvider": "FARGATE_SPOT",
                        "weight": 1,
                        "base": 0
                    }
                ],
                "platformVersion": "1.4.0",
                "platformFamily": "Linux",
                "networkConfiguration": {
                    "awsvpcConfiguration": {
                        "subnets": [
                            "subnet-123456abcd"
                        ],
                        "securityGroups": [
                            "sg-123abcd"
                        ],
                        "assignPublicIp": "ENABLED"
                    }
                },
                "rolloutState": "COMPLETED",
                "rolloutStateReason": "ECS deployment ecs-svc/1915205208403184481 completed."
            }
        ],
        "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS",
        "events": [
            {
                "id": "0e5ade28-696f-4c79-812c-efb79ec94a1d",
                "createdAt": "2024-09-01T01:45:59.048000+09:00",
                "message": "(service hato-ecs-service) has reached a steady state."
            }
        ],
        "createdAt": "2024-07-24T17:25:53.191000+09:00",
        "placementConstraints": [],
        "placementStrategy": [],
        "networkConfiguration": {
            "awsvpcConfiguration": {
                "subnets": [
                    "subnet-123456abcd"
                ],
                "securityGroups": [
                    "sg-123abcd"
                ],
                "assignPublicIp": "ENABLED"
            }
        },
        "schedulingStrategy": "REPLICA",
        "deploymentController": {
            "type": "ECS"
        },
        "createdBy": "arn:aws:iam::123456789012:role/hato",
        "enableECSManagedTags": true,
        "propagateTags": "NONE",
        "enableExecuteCommand": false
    }
}

参考資料

コンソールを使用した Amazon ECS サービスの更新 - Amazon Elastic Container Service

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.